﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using com.SyncConfiguration;
using System.Web.Caching;

namespace JumptonSFA.Service
{
    public class Global : System.Web.HttpApplication
    {
        static CacheItemRemovedCallback onRemove = null;
        static HttpContext context = null;

        protected void RemovedCallback(String k, Object v, CacheItemRemovedReason r)
        {
            //System.Collections.Generic.Dictionary<string, SyncConfigurationSection> syncConfig = context.Cache["SyncConfiguration"] as System.Collections.Generic.Dictionary<string, SyncConfigurationSection>;

            object obj = SyncConfiguration.Section;
            context.Cache.Insert("SyncConfiguration", obj, new CacheDependency(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile), DateTime.Now.AddHours(6), Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.High,
                onRemove);
        }


        protected void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            //在应用程序启动时运行的代码
            Jumpton.JumptonException.ExceptionManager.InitApplicationException();
            //this.BeginRequest += new EventHandler(global_asax_BeginRequest);
            Jumpton.Configuration.AppConfiguration.Init(Jumpton.Common.ConfigurationType.Xml, AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);

            SyncConfiguration.Init(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
            onRemove = new CacheItemRemovedCallback(RemovedCallback);
            context = this.Context;
            RemovedCallback(null, null, new CacheItemRemovedReason());
        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {
            AppDomain.Unload(AppDomain.CurrentDomain);
        }
    }
}